use std::collections::HashMap;

fn main() {
    let mut a:Vec<i32> = vec![0,1,2];

    a.push(3);

    // 读取

    println!("a[3] is :{}", &a[3]);

    match a.get(3) {
        Some(num) => {println!("a[3] is :{}",num);},
        None => {println!("Not Find!!")},
    }

    // println!("a[100] is :{}", &a[100]);
    match a.get(100) {
        Some(num) => {println!("a[100] is :{}",num);},
        None => {println!("Not Find!!")},
    }

    // let first = &a[0];
    a.push(4);
    // println!("first is : {}",first); 报错！

    // 遍历
    for i in &a {
        println!("{}", i);
    }

    // 可变遍历
    for i in &mut a {
        *i = *i + 50;
    }

    for i in &a {
        println!("{}", i);
    }

    // 声明及插入
    let mut a = HashMap::new();
    a.insert(String::from("111"), 111);
    
    // 所有权问题
    let mut a = HashMap::new();
    let first_str = String::from("THIS is first");
    a.insert("1",first_str);
    // println!("{}",first_str);

    // 获取 遍历
    a.insert("2", String::from("THIS is second"));

    if let Some(s) = a.get("1") {
        println!("1 is {} ;",s);
    } else {
        println!("Not find 1!")
    }

    for (k,v) in &a {
        println!("k : {} is v: {} ;",k ,v);
    }

    // entry or_insert
    a.entry("3").or_insert(String::from("None"));
    println!("a is {:?}",a);
    a.entry("3").or_insert(String::from("third"));
    println!("a is {:?}",a);
    let third = a.entry("3").or_insert(String::from("third"));
    *third = String::from("third");
    println!("a is {:?}",a);

    println!("Hello, world!");

    // 所有权验证 vector
    let first = String::from("ffff");
    let mut vecs = vec![String::from("ddd")];
    vecs.push(first);
    // println!(first); 报错

    // 所有权验证 hashmap
    let first = String::from("ffff");
    let mut vecs = HashMap::new();
    vecs.insert("1", first);
    // println!(first); 报错
}
